package stateAAs.textures {
	import flash.geom.Point;
	import org.agony2d.Agony;
	import org.agony2d.gpu.core.ImageAA;
	import org.agony2d.gpu.FusionAA;
	import org.agony2d.gpu.StateAA;
	import org.agony2d.gpu.TingedImageAA;
	import org.agony2d.gpu.UntingedImageAA;
	import org.agony2d.input.KeyboardManager;
	import org.agony2d.input.TouchManager;
	import org.agony2d.notify.AEvent;
	
public class Atlas_StateAA extends StateAA {
  
	/** overwritable... */
	override public function get smoothing() : Boolean {
		return true
	}
	
	/** overwritable... */
	override public function get tinted() : Boolean {
		return true
	}
	
	/** overwrite... */
	override public function get fullTex() : String {
		return "atlas"
	}
	
	/** overwrite... */
	override public function enter() : void {
		var tintImg:TingedImageAA
		
		mImgA = new TingedImageAA
		this.group.addNode(mImgA)
		//mImgA.alpha = 0.8
		//mImgA.pivotX = 110
		//mImgA.pivotY = 110
		
		mImgA.textureData = "flight_14"
		mImgA.x = 110
		mImgA.y = 110
		//trace(mImgA.width, " | " , mImgA.height)
		//mImgA.scaleX = 1.2
		//mImgA.rotation = 45
		mImgA.pivotX = mImgA.pivotY = 50
		
		trace(mImgA.localToGlobal(0,0))
		trace(mImgA.fusion.localToGlobal(0,0))
		trace(mImgA.world.localToGlobal(0,0))
		
		//mImgA.interactive = false
		mImgA.addEventListener(AEvent.PRESS, onImgTouch)
		mImgA.addEventListener(AEvent.RELEASE, onImgTouch)
		mImgA.addEventListener(AEvent.MOVE, onImgTouch)
		mImgA.addEventListener(AEvent.OVER, onImgTouch)
		mImgA.addEventListener(AEvent.LEAVE, onImgTouch)
		mImgA.addEventListener(AEvent.CLICK, onImgTouch)
		
		//this.group.world.addEventListener(AEvent.PRESS, onPressWorld)
		
		//Agony.process.addEventListener(AEvent.ENTER_FRAME, onUpdate)
		KeyboardManager.getInstance().getState().release.addEventListener("Q", onSwap)
		KeyboardManager.getInstance().getState().release.addEventListener("T", onTex)
	}
	
	override public function exit():void {
		//Agony.process.removeEventListener(AEvent.ENTER_FRAME, onUpdate)
		KeyboardManager.getInstance().getState().release.removeEventListener("Q", onSwap)
		KeyboardManager.getInstance().getState().release.removeEventListener("T", onTex)
	}
	
	
	private var mImgA:TingedImageAA
	private var mFusionA:FusionAA, mFusionB:FusionAA
	private var mFusionC:FusionAA, mFusionD:FusionAA
	private var mIndex:int
	
	
	
	private function onUpdate(e:AEvent):void {
		mImgA.rotation += 0.2
	}
	
	private function onPressWorld(e:AEvent):void {
		var p:Point = mImgA.globalToLocal(this.group.world.currTouch.stageX - this.group.world.x , this.group.world.currTouch.stageY)
		trace(p)
	}
	
	private function onImgTouch(e:AEvent):void {
		trace("Img: " + e.type)
	}
	
	private function onSwap(e:AEvent):void {
		if (++mIndex == 14) {
			mIndex = 0
			
		}
		if (mIndex == 0) {
			mImgA.textureData = "flight_14"
		}
		else if (mIndex == 1) {
			mImgA.textureData = "flight_1"
		}
		else if (mIndex == 2) {
			mImgA.textureData = "flight_2"
		}
		else if (mIndex == 3) {
			mImgA.textureData = "flight_3"
		}
		else if (mIndex == 4) {
			mImgA.textureData = "flight_4"
		}
		else if (mIndex == 5) {
			mImgA.textureData = "flight_5"
		}
		else if (mIndex == 6) {
			mImgA.textureData = "flight_6"
		}
		else if (mIndex == 7) {
			mImgA.textureData = "flight_7"
		}
		else if (mIndex == 8) {
			mImgA.textureData = "flight_8"
		}
		else if (mIndex == 9) {
			mImgA.textureData = "flight_9"
		}
		else if (mIndex == 10) {
			mImgA.textureData = "flight_10"
		}
		else if (mIndex == 11) {
			mImgA.textureData = "flight_11"
		}
		else if (mIndex == 12) {
			mImgA.textureData = "flight_12"
		}
		else if (mIndex == 13) {
			mImgA.textureData = "flight_13"
		}
	}
	
	private function onTex(e:AEvent):void {
		
	}
}
}